package com.yz.platform.modules.biz.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yz.platform.common.utils.PageUtils;
import com.yz.platform.common.utils.Query;
import com.yz.platform.common.utils.R;
import com.yz.platform.modules.biz.entity.OrderDetailsEntity;
import com.yz.platform.modules.biz.service.OrderDetailsService;
import com.yz.platform.modules.sys.controller.AbstractController;


/**
 * @author lin
 * @email
 * @date 2017-10-15 16:00:56
 */
@RestController
@RequestMapping("orderdetails")
public class OrderDetailsController extends AbstractController {
    @Autowired
    private OrderDetailsService orderDetailsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("orderdetails:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<OrderDetailsEntity> orderDetailsList = orderDetailsService.queryList(query);
        int total = orderDetailsService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(orderDetailsList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("orderdetails:info")
    public R info(@PathVariable("id") Integer id) {
        OrderDetailsEntity orderDetails = orderDetailsService.queryObject(id);

        return R.ok().put("orderDetails", orderDetails);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("orderdetails:save")
    public R save(@RequestBody OrderDetailsEntity orderDetails) {
        orderDetailsService.save(orderDetails);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("orderdetails:update")
    public R update(@RequestBody OrderDetailsEntity orderDetails) {
        orderDetailsService.update(orderDetails);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("orderdetails:delete")
    public R delete(@RequestBody Integer[] ids) {
        orderDetailsService.deleteBatch(ids);

        return R.ok();
    }

}
